/**
 * ProfileViewer
 *
 * This window draw the profile information on screen
 *
 * The current implementation draw a transparent screen without 
 * border, at the center of the window draw the alias and around 
 * this draw the tags in a random way.
 */
class ProfileViewer extends Window
{
  // The current font
  private PFont font = loadFont();
  
  // The profile
  private MicroProfile profile;
  
  // Tags positions in the screen
  private int[][] tagPositions;

  /**
   * Draw the profile values
   */
  void draw()
  {
    // If the profile is not set, do nothing
    if(profile == null)
      return;
    
    // Save current transformations
    pushMatrix();
    
    // Go to the center of the window
    translate(x,y);
    
    // Set font
    textFont(font);
    
    // Draw the profile alias
    textAlign(CENTER);    
    fill(0x00FF00);
    text(profile.alias,0,font.height);
    
    // Draw each tag in white around the alias
    fill(0xFFFFFF);
    for(int i=0; i<profile.numTags; i++)
    {
      int x = tagPositions[i][0];
      int y = tagPositions[i][1];      
      text(profile.tags[i],x,y);
    }

    // Restore transformations
    popMatrix();
  }
  
  /**
   * Set the profile to show
   *
   * @param profile Profile to show
   */
  void profile(MicroProfile profile)
  {
    // Set profile
    this.profile = profile;
    
    // Create an array with the (x,y) position 
    // for each tag
    tagPositions = new int[profile.numTags][2];
    
    // Fill the array with random numbers 
    // the position of each tag depends of the window size
    for(int i=0; i<profile.numTags; i++)
    {
      tagPositions[i][0] = random(-width/2,width/2);
      tagPositions[i][1] = random(-height/2,height/2);            
    }
  }  
}
